
// var CryptoJS = require("crypto-js");
import CryptoJS from "@/utils/crypto-js/index.js";
let keya ="ca751e7aeaf600700933bcb1e609a455";
let iva = "0933bcb1e609a455";
let aaa = 'YXl6OW9jYWt2YWQ5ZmZidGZvbG1lZWtwMDlxMDdicnZ0bjM0Nmp6MHR2NmFrYnY2dWFpenViMzl5NHEzM2wzNA==';
let bbb = 'cGEwOWpnb3pnbzMxc2tnZDFvYmowNXgyYmQ4MzdreWlreDV3NHk1MnU0NXl4OXpk';
let parsedWordArray = CryptoJS.enc.Base64.parse(aaa);
let key = (parsedWordArray.toString(CryptoJS.enc.Utf8)+keya).substring(11,43);
let parsedWordArray1 = CryptoJS.enc.Base64.parse(bbb);
let iv = (parsedWordArray1.toString(CryptoJS.enc.Utf8)+iva).substring(17,33);
 
 //此处key 和 iv 已混淆编写  防止反编译！  请不要明文写 key 和 iv

//加密
const encrypt = (text)=>{
    return CryptoJS.AES.encrypt(text,CryptoJS.enc.Utf8.parse(key),{
        iv:CryptoJS.enc.Utf8.parse(iv),
        mode:CryptoJS.mode.CBC,
        padding:CryptoJS.pad.Pkcs7
    })
}


//解密方法 ok
const decrypt =  (text)=>{
    var result = CryptoJS.AES.decrypt(text,CryptoJS.enc.Utf8.parse(key),{
        iv:CryptoJS.enc.Utf8.parse(iv),
        mode:CryptoJS.mode.CBC,
        padding:CryptoJS.pad.Pkcs7
    })
    return result.toString(CryptoJS.enc.Utf8)
}

// export default {
	
// }


module.exports = {
  decrypt,//解密
  encrypt,//加密
}

/**
 * 下面的是使用的测试的例子
 * */
// var text="ni你好hao";
// var encoded=encrypt(text)
// console.log(encoded.toString());
// console.log(decrypt(encoded))



//解密
// var encoded11 = `iwsO+0Qivc8uXVGzv\/lw1maiNYGSqri8rxK0SX5NhE1XwY72XZ3EN5o0u7PVpzD9wvQy4iznEdpvtIeZazy1ip9d71xg2gjegTwq0HC+NlvTVgNBmQ2elt+I3aIXFqgJaidMplKzMN9UMhe4ywuIqoA541sEbIwfcFgbTFt5PE6mDTHok\/bNt65b32B8viAyHmAaS\/c0Vfd7E1bg7+DJ60J5htQtRUELRBTOHgD3RFE=`;
// console.log(decrypt(encoded11))


//加密
//内容
//let textsf = `{"phone_on":"17521069874","password":"175343243"}`;
//console.info(encrypt(textsf));


// var text=`{"phone_on":"17521069874","password":"175343243"}`;
// var encoded=encrypt(text)
// console.log(encoded.toString());



//j8vX2smiwBZ5dPRJb/kyjQnTCDUtHpiBspztL4oR89rKLqz6chZbt8Gq5QHbhx1KaPxGjsmYWC53Waei4TWy4g== 结果
//j8vX2smiwBZ5dPRJb\/kyjQnTCDUtHpiBspztL4oR89rKLqz6chZbt8Gq5QHbhx1KaPxGjsmYWC53Waei4TWy4g== 结果